package com.cyy.vue.service.impl;

import com.cyy.vue.MyResult;
import com.cyy.vue.entry.CloudTest;
import com.cyy.vue.entry.User;
import com.cyy.vue.mapper.TestMapper;
import com.cyy.vue.mapper.UserMapper;
import com.cyy.vue.service.TestService;
import com.cyy.vue.service.UserService;
import com.cyy.vue.util.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public MyResult login(User user) {
        MyResult myResult = new MyResult();
        String userName = user.getUserName();
        String password = user.getPassword();
        List<User> list = userMapper.login(userName,password);
        if(!list.isEmpty()){
            myResult.setCode(200);
            myResult.setList(list);
            myResult.setObj(list.get(0));
            myResult.setMsg("登录成功");
            myResult.setToken(MyUtils.sign(userName,user.getId()));
        }else{
            myResult.setCode(500);
            myResult.setMsg("登录失败");
        }
        return myResult;
    }


}
